﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RMS.Utils.Dicom.Commen;

namespace RMS.Utils.Dicom.DataStructure
{
    public class Value
    {
        #region [Properties]
        private ValueLength ValueLength;
        private VR VR;

        public bool IsString
        {
            get
            {
                return
                    VR.Name.Equals("AE") || VR.Name.Equals("AS") ||
                    VR.Name.Equals("CS") || VR.Name.Equals("DS") ||
                    VR.Name.Equals("LO") || VR.Name.Equals("LT") ||
                    VR.Name.Equals("SH") || VR.Name.Equals("ST") ||
                    VR.Name.Equals("UI") || VR.Name.Equals("UT") ||
                    VR.Name.Equals("PN");
            }
        }
        public bool IsNumeric
        {
            get
            {
                return
                    VR.Name.Equals("AT") || VR.Name.Equals("FL") ||
                    VR.Name.Equals("FD") || VR.Name.Equals("IS") ||
                    VR.Name.Equals("OF") || VR.Name.Equals("OW") ||
                    VR.Name.Equals("OB") || VR.Name.Equals("SS") ||
                    VR.Name.Equals("SL") || VR.Name.Equals("UL") ||
                    VR.Name.Equals("US");
            }
        }
        public bool IsDate
        {
            get
            {
                return VR.Name.Equals("DA") || VR.Name.Equals("DT");
                // || VR.Name.Equals("TM"); ;
            }
        }

        private object valueFiled = "No Data Found";
        public object ValueFiled
        {
            get
            {
                return valueFiled;
            }
        }
        #endregion

        #region [Constructor]
        public Value(VR vRName, ValueLength valueLength)
        {
            ValueLength = valueLength;
            VR = vRName;
            readValue();
        }
        #endregion

        #region [HelperMethod]
        private void readValue()
        {
            if (ValueLength.Length > 0)
                GetValue(StreamFile.Read(ValueLength.Length));
        }
        private void GetValue(byte[] data)
        {
            if ((IsString || VR.IsImplicit) && !StreamFile.IsPixelData)
            {
                valueFiled = data.GetString();
                return;
            }
            else if (StreamFile.IsPixelData)
            {
                StreamFile.PixelData = data;
                StreamFile.IsPixelData = false;
                return;
            }
            else if (IsNumeric)
            {
                valueFiled = data.ToUInt16();
                return;
            }
            else if (IsDate)
            {
                valueFiled = data.ToDateTime();
                return;
            }

        }
        #endregion

    }
}
